An environmentally specific type of locomotion (e.g., bipedal or quadrupedal walking) is effective only under the specified environments. However, other conditions could cause physical body constraints and decrease mobility. Despite these constraints, legged robots are desired with high overall mobility such that they can walk under various conditions. Thus, a combination of types of locomotion is needed to maximize overall mobility. We have developed a gorilla-type robot, which can switch between bipedal and quadrupedal walking. A selection technique to optimize locomotion choice would be beneficial to the robot, which will experience challenging situations when walking through complex terrains, receiving disturbances, or malfunctioning. We present a selection algorithm for locomotion (SAL) that improves overall mobility by autonomously selecting the optimal locomotion. The falling risk of each locomotion mode is evaluated with a Bayesian network to represent the robot's situation. The evaluation function for the SAL determines the optimal locomotion choice based on falling risk and moving speed. In this paper, the SAL is used for two state variables of locomotion: gait (Ga-SAL) and speed (Sp-SAL). Both the simulations and experiments validated that the robot traveled efficiently in complex environments.